/**
 * @author FengLei.You
 */
var Me = {	
	displayCanvas:null,	
	context2d:null,
};

Me.extend = function(parent,child){
	//用一个简单对象传递.减少内存分配
	var transferObj = function(){};
	transferObj.prototype = parent.prototype;
	
	child.prototype = new transferObj();
	child.prototype.constructor = child;
	
	//备用属性.在子类中,可以直接访问父类方法
	child.parent = parent.prototype;
}
Me.trace=function(text){
	if(typeof(console)!='undefined'){
		console.log(text);
	}
}

Me.iterateCall=function(callbacks,obj,trueExit){
	if(callbacks&&callbacks.length>0){
		for(var i=0;i<callbacks.length;i++){
			var rt = callbacks[i](obj);
			if(trueExit && rt)return rt;
		}
	}
}

/**
 * 初始化整个框架
 */
Me.init=function(opt){	
	Me.displayCanvas=document.getElementById(opt.canvasId);
	Me.displayCanvas.width=opt.width;
	Me.displayCanvas.height=opt.height;
	Me.context2d=Me.displayCanvas.getContext('2d');
	
	Me.stage=new Stage({mainLoopTime:1000});
	
	Me.layerManager=new LayerManager({
		top:0,
		left:0,
		width:opt.width,
		height:opt.height,
	});
	
	Me.resourceManager=new ResourceManager({
		context:Me.context2d,
		title:'HappyElements',
	});
	Me.resourceManager.load(opt.resources,
		function(){
			if(opt.callback){
				opt.callback();
			}
		}
	);
}
